/*
*    Phantom Test Driver v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
 * PTDMessageBox.java
 *
 * Created on September 4, 2007, 9:11 PM
 */

package ptd;

import javax.swing.ImageIcon;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author  John
 */
public class PTDMessageBox extends javax.swing.JFrame {
    
    /** Creates new form PTDMessageBox */
    public PTDMessageBox(String Message) {
        initComponents();
        ImageIcon a = PTDImageLoader.getImageIcon(PTDImageLoader.IMG_PTD_ICON);
        setIconImage(a.getImage());
        this.setSize(286, 215);
        OKButton.setText("OK");
        PTDLabel.setText("Message");
        EvalLabel.setText(Message);
        a = PTDImageLoader.getImageIcon(PTDImageLoader.IMG_PTD_LABEL);
        IconLabel.setIcon(a);
        IconLabel.setText("");
   
        OKButton.requestFocusInWindow();
        getRootPane().setDefaultButton((OKButton));
        
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        this.setLocation((dim.width-286)/2, (dim.height-190)/2);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        OKButton = new javax.swing.JButton();
        PTDLabel = new javax.swing.JLabel();
        IconLabel = new javax.swing.JLabel();
        EvalLabel = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Message: Phantom Test Driver");
        setAlwaysOnTop(true);
        setResizable(false);
        getContentPane().setLayout(null);

        OKButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OKButtonActionPerformed(evt);
            }
        });
        getContentPane().add(OKButton);
        OKButton.setBounds(100, 160, 75, 23);

        PTDLabel.setFont(new java.awt.Font("Arial Black", 0, 24));
        PTDLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        getContentPane().add(PTDLabel);
        PTDLabel.setBounds(50, 30, 180, 30);
        getContentPane().add(IconLabel);
        IconLabel.setBounds(10, 10, 60, 60);

        EvalLabel.setBackground(new java.awt.Color(212, 208, 200));
        EvalLabel.setEditable(false);
        EvalLabel.setFont(new java.awt.Font("Courier", 1, 13));
        EvalLabel.setLineWrap(true);
        EvalLabel.setWrapStyleWord(true);
        EvalLabel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        EvalLabel.setOpaque(false);
        getContentPane().add(EvalLabel);
        EvalLabel.setBounds(10, 70, 260, 80);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKButtonActionPerformed
        bWaiting = false;
        dispose();
    }//GEN-LAST:event_OKButtonActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PTDMessageBox("Message").setVisible(true);
            }
        });
    }
    
    public static void MessageBox(String Message){
        PTDMessageBox aBox = new PTDMessageBox(Message);
        aBox.setVisible(true);
    }

    public static void MessageBoxWait(String Message){
        PTDMessageBox aBox = new PTDMessageBox(Message);
        aBox.setVisible(true);
        aBox.doModal();
    }

    
    public void doModal(){
        bWaiting = true;
        setAlwaysOnTop(true);
        while(bWaiting){
            try {
                Thread.currentThread().sleep(10);
            } catch (InterruptedException ex) {
                Main.debug_out(ex.getMessage());
            }
        }
    }
    
    private boolean bWaiting = false;
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea EvalLabel;
    private javax.swing.JLabel IconLabel;
    private javax.swing.JButton OKButton;
    private javax.swing.JLabel PTDLabel;
    // End of variables declaration//GEN-END:variables
    
}
